<?php  namespace Common\Model;

use Hdphp\Model\Model;

class Cate extends Model{
	protected $table = 'category';
	
	protected $validate = array(
	
		array('cname','required','分类名称不能为空',3,3),
	
	);
	
	public function addData(){
		if(!$this->create()) return false;
		$this->add();
		return true;
	}
	
	public function editData(){
		if(!$this->create()) return false;
		$this->save();
		return true;
	}
	
	
	public function getNoMy($cid){
		//拿到要当前分类和子分类的cid
		$cids = $this->getSon($this->get(),$cid);
		//把当前的分类也押进数组
		$cids [] = $cid;
		//把数组专为字符串
		$strCids = implode(',', $cids);
		//取得cid不属于字符串里分类数据 
		return $this->where("cid NOT IN (".$strCids.")")->get();
	}
	
	public function getSon($data,$cid){
		$temp = array();
		foreach ($data as $v) {
			if($v['pid'] == $cid){
				$temp[] = $v['cid'];
				$temp = array_merge($temp,$this->getSon($data,$v['cid']));
			}
		}
		return $temp;
	}
}



 ?>